package com.player.entity;

import java.util.Date;

import javax.persistence.Id;

import com.googlecode.objectify.annotation.Indexed;
import com.googlecode.objectify.annotation.Unindexed;

public class GameResult {

	@Id
	Long id;

	@Unindexed
	int setsWonByCreator;

	@Unindexed
	int setsWonByOpponent;

	@Indexed
	boolean confirmedByOpponent;

	@Unindexed
	Date dateConfirmedByOpponent;

	@Unindexed
	Date dateResultCreated;

	public GameResult() {
	}

	public GameResult(int setsWonByCreator, int setsWonByOpponent) {
		super();
		this.setsWonByCreator = setsWonByCreator;
		this.setsWonByOpponent = setsWonByOpponent;
		this.dateResultCreated = new Date();
	}

	public int getSetsWonByCreator() {
		return setsWonByCreator;
	}

	public int getSetsWonByOpponent() {
		return setsWonByOpponent;
	}

	public boolean isConfirmedByOpponent() {
		return dateConfirmedByOpponent != null && confirmedByOpponent == true;
	}

	public Date getDateConfirmedByOpponent() {
		return dateConfirmedByOpponent;
	}

	public void confirm() {
		confirmedByOpponent = true;
		dateConfirmedByOpponent = new Date();
	}

	public Date getDateResultCreated() {
		return dateResultCreated;
	}

	@Override
	public String toString() {
		return "GameResult [confirmedByOpponent=" + isConfirmedByOpponent() + ", dateResultCreated="
				+ dateResultCreated + ", setsWonByCreator=" + setsWonByCreator + ", setsWonByOpponent="
				+ setsWonByOpponent + "]";
	}

}
